import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:reader_app/content_pager.dart';
import 'package:reader_app/custum_appbar.dart';

///页面导航框架
class TapNavigator extends StatefulWidget {
  @override
  _TapNavigatorState createState() => _TapNavigatorState();
}

class _TapNavigatorState extends State<TapNavigator> {
  int _currentIndex = 4;
  final ContentPagerController contentPagerController = ContentPagerController();

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      body: new Container(
        decoration: new BoxDecoration(
            gradient: new LinearGradient(
                colors: [Color(0xffe2e2e2), Color(0xff2f1f2f)], begin: Alignment.topCenter, end: Alignment.bottomCenter)),
        child: new Column(
          children: <Widget>[
            new CustomAppBar(),
            new Expanded(
              child: new ContentPager(
                _currentIndex,
                (index) {
                  setState(() {
                    _currentIndex = index;
                  });
                },
                contentPagerController: contentPagerController,
              ),
            )
          ],
        ),
      ),
      bottomNavigationBar: new BottomNavigationBar(
        items: [
          _createBottomItem("本周", Icons.folder, 0),
          _createBottomItem("分享", Icons.explore, 1),
          _createBottomItem("免费", Icons.donut_small, 2),
          _createBottomItem("我的", Icons.person, 3),
          _createBottomItem("测试", Icons.add_to_queue, 4),
        ],
        onTap: (index) {
          setState(() {
            _currentIndex = index;
            contentPagerController.jump2Page(index);
          });
        },
        currentIndex: _currentIndex,
        type: BottomNavigationBarType.fixed,
      ),
    );
  }

  BottomNavigationBarItem _createBottomItem(String title, IconData icon, int index) {
    return new BottomNavigationBarItem(
        title: new Text(
          title,
          style: new TextStyle(color: _currentIndex == index ? Colors.cyan : Colors.grey),
        ),
        icon: new Icon(
          icon,
          color: Colors.grey,
        ),
        activeIcon: new Icon(
          icon,
          color: Colors.cyan,
        ));
  }
}
